package de.acando.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Scrollbar;
import java.awt.Toolkit;
import java.util.Date;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.GroupLayout;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;

import org.omg.CORBA.Bounds;

public class Home extends JFrame{
	
	private JMenuBar bar = new JMenuBar();
	
	private JMenu menu = new JMenu("Menü");
	
	private JMenuItem itemSuchen = new JMenuItem("Suchen");
	private JMenuItem itemBeenden = new JMenuItem("Beenden");
	
	private JPanel panelInfo = new JPanel();
	private JPanel panelInfoInfo = new JPanel();
	private JPanel panelIconInfo = new JPanel();
	private JPanel panelAllgInfoInfo = new JPanel();
	private JPanel panelKontaktInfo = new JPanel();
	private JPanel panelInInfoInfo = new JPanel();
	private JPanel panelBeitrag = new JPanel();
	private JPanel panelBeitraege = new JPanel();
	private JPanel panelEditor = new JPanel();
	private JPanel panelButton = new JPanel();
	
	private TitledBorder titleInfo = new TitledBorder("Info");
	private TitledBorder titleAllgInfo = new TitledBorder("Allgemeine Info");
	private TitledBorder titleKontakt = new TitledBorder("Kontakt");
	private TitledBorder titlebeitrag = new TitledBorder("Beiträge");
	private TitledBorder titleEditor = new TitledBorder("Kommentar");
	
	private JButton buttonSenden = new JButton("Senden");
	
	private JLabel labelVorname = new JLabel("Vorname:");
	private JLabel labelgetVorname = new JLabel("");
	private JLabel labelNachname = new JLabel("Nachname:");
	private JLabel labelgetNachname = new JLabel("");
	private JLabel labelSeit = new JLabel("Bei Acando seit: ");
	private JLabel labelgetSeit = new JLabel("April 2014");
	private JLabel labelBeiAcando = new JLabel("bei Acando");
	private JLabel labelStatus = new JLabel("Rolle:");
	private JLabel labelgetStatus = new JLabel("Praktikant");
	private JLabel labelEmail = new JLabel("Email:");
	private JLabel labelgetEmail = new JLabel("riad.hassani.external@acando.de");
	private JLabel labelTelefon = new JLabel("Telefon:");
	private JLabel labelgetTelefon = new JLabel("01577-1724028");
	private JLabel labelIcon;

	
	private ImageIcon icon;
	
	private JTextArea editorText;
	
	private JTabbedPane tabpane = new JTabbedPane();
	
	
	public Home(){
		bestandteileAnordnen();
		erstelleFenster();
		//ereignissensorenAnmeldung();
		new Bilder(tabpane);
		new Video(tabpane);
		new Freunde(tabpane);
	}
	
	private void erstelleFenster(){
		
		setTitle("Acando");
		Toolkit tk = Toolkit.getDefaultToolkit(); 
		int xSize = ((int) tk.getScreenSize().getWidth());
		int ySize = ((int) tk.getScreenSize().getHeight());  
		setSize(xSize, ySize);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		getContentPane().setBackground(Color.white);
		tabpane.setBackground(Color.white);
		add(tabpane);
		setVisible(true);
		setResizable(true);
	}

	private void bestandteileAnordnen(){
		infoTabAnordnen();
	}

	private void infoTabAnordnen() {
		GroupLayout infoLayout = new GroupLayout(panelInfo); 
		panelInfo.setLayout(infoLayout);
		panelInfo.add(new JScrollPane());
		panelInfo.setBackground(Color.white);

		infoLayout.setAutoCreateGaps(true);
		infoLayout.setAutoCreateContainerGaps(true);

		infoLayout.setVerticalGroup(infoLayout.createSequentialGroup()
				.addComponent(panelInfoInfo)
				.addComponent(panelAllgInfoInfo)
				.addComponent(panelKontaktInfo)
				.addComponent(panelBeitrag));

		infoLayout.setHorizontalGroup(infoLayout.createParallelGroup()
				.addComponent(panelInfoInfo)
				.addComponent(panelAllgInfoInfo)
				.addComponent(panelKontaktInfo)
				.addComponent(panelBeitrag));

		infoAnordnen();
		AlgInfoInfoAnordnen();
		kontaktInfoAnordnen();
		beitragAnordnen();
		tabpane.addTab("Info", null, panelInfo, "Zeigt Informationen über deinen Profil an.");
	}
	
	private void infoAnordnen(){
		titleInfo.setBorder(new LineBorder(Color.orange));
		panelInfoInfo.setBorder(titleInfo);
		panelInfoInfo.setLayout(new FlowLayout(FlowLayout.LEFT));
		panelInfoInfo.add(panelIconInfo);
		panelInfoInfo.add(panelInInfoInfo);
		panelInfoInfo.setBackground(Color.white);
		panelIconAnordnen();
		panelInInfoInfoAnordnen();
	}
	
	private void panelIconAnordnen(){
		icon = new ImageIcon("/home/riad/workspace/Bilder/bild.jpg");
		icon.setImage(icon.getImage().getScaledInstance(150, 200, Image.SCALE_DEFAULT));
		labelIcon = new JLabel(icon);
		labelIcon.setBorder(new LineBorder(Color.orange));
		panelIconInfo.setBorder(new LineBorder(Color.orange));
		panelIconInfo.add(labelIcon);
	}
	
	private void panelInInfoInfoAnordnen(){
		GroupLayout inInfoInfoLayout = new GroupLayout(panelInInfoInfo); 
		panelInInfoInfo.setLayout(inInfoInfoLayout);
		panelInInfoInfo.setBackground(Color.white);
		
		inInfoInfoLayout.setAutoCreateGaps(true);
		inInfoInfoLayout.setAutoCreateContainerGaps(true);

		inInfoInfoLayout.setVerticalGroup(inInfoInfoLayout.createSequentialGroup()
				.addGroup(inInfoInfoLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
						.addComponent(labelVorname)
						.addComponent(labelgetVorname))
				.addGroup(inInfoInfoLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
						.addComponent(labelNachname)
						.addComponent(labelgetNachname)));

		inInfoInfoLayout.setHorizontalGroup(inInfoInfoLayout.createParallelGroup().addGroup(inInfoInfoLayout.createSequentialGroup()
				.addGroup(inInfoInfoLayout.createParallelGroup(GroupLayout.Alignment.LEADING, true)
						.addComponent(labelVorname, GroupLayout.DEFAULT_SIZE,GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(labelNachname, GroupLayout.DEFAULT_SIZE,GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
				.addGroup(inInfoInfoLayout.createParallelGroup(GroupLayout.Alignment.LEADING, true)
						.addComponent(labelgetVorname, GroupLayout.DEFAULT_SIZE,GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(labelgetNachname, GroupLayout.DEFAULT_SIZE,GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))));
	}
	
	private void AlgInfoInfoAnordnen(){
		titleAllgInfo.setBorder(new LineBorder(Color.orange));
		panelAllgInfoInfo.setBorder(titleAllgInfo);
		
		GroupLayout algInfoInfoLayout = new GroupLayout(panelAllgInfoInfo); 
		panelAllgInfoInfo.setLayout(algInfoInfoLayout);
		panelAllgInfoInfo.setBackground(Color.white);
		algInfoInfoLayout.setAutoCreateGaps(true);
		algInfoInfoLayout.setAutoCreateContainerGaps(true);

		algInfoInfoLayout.setVerticalGroup(algInfoInfoLayout.createSequentialGroup()
				.addGroup(algInfoInfoLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
						.addComponent(labelSeit))
						//.addComponent(labelgetSeit)
						//.addComponent(labelBeiAcando))
				.addGroup(algInfoInfoLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
						.addComponent(labelStatus)));
						//.addComponent(labelgetStatus)));

		algInfoInfoLayout.setHorizontalGroup(algInfoInfoLayout.createParallelGroup().addGroup(algInfoInfoLayout.createSequentialGroup()
				.addGroup(algInfoInfoLayout.createParallelGroup(GroupLayout.Alignment.LEADING, true)
						.addComponent(labelSeit, GroupLayout.DEFAULT_SIZE,GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(labelStatus, GroupLayout.DEFAULT_SIZE,GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))));
				//.addGroup(algInfoInfoLayout.createParallelGroup(GroupLayout.Alignment.LEADING, true)
						//.addComponent(labelgetSeit, GroupLayout.DEFAULT_SIZE,GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
					//	.addComponent(labelgetStatus, GroupLayout.DEFAULT_SIZE,GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))));
				//.addGroup(algInfoInfoLayout.createParallelGroup(GroupLayout.Alignment.LEADING, true)
						//.addComponent(labelBeiAcando, GroupLayout.DEFAULT_SIZE,GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))));
	}
	
	private void kontaktInfoAnordnen(){
		titleKontakt.setBorder(new LineBorder(Color.orange));
		panelKontaktInfo.setBorder(titleKontakt);
		
		GroupLayout kontaktInfoLayout = new GroupLayout(panelKontaktInfo); 
		panelKontaktInfo.setLayout(kontaktInfoLayout);
		panelKontaktInfo.setBackground(Color.white);
		kontaktInfoLayout.setAutoCreateGaps(true);
		kontaktInfoLayout.setAutoCreateContainerGaps(true);

		kontaktInfoLayout.setVerticalGroup(kontaktInfoLayout.createSequentialGroup()
				.addGroup(kontaktInfoLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
						.addComponent(labelEmail))
						//.addComponent(labelgetSeit)
						//.addComponent(labelBeiAcando))
				.addGroup(kontaktInfoLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
						.addComponent(labelTelefon)));
						//.addComponent(labelgetStatus)));

		kontaktInfoLayout.setHorizontalGroup(kontaktInfoLayout.createParallelGroup().addGroup(kontaktInfoLayout.createSequentialGroup()
				.addGroup(kontaktInfoLayout.createParallelGroup(GroupLayout.Alignment.LEADING, true)
						.addComponent(labelEmail, GroupLayout.DEFAULT_SIZE,GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(labelTelefon, GroupLayout.DEFAULT_SIZE,GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))));
				//.addGroup(algInfoInfoLayout.createParallelGroup(GroupLayout.Alignment.LEADING, true)
						//.addComponent(labelgetSeit, GroupLayout.DEFAULT_SIZE,GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
					//	.addComponent(labelgetStatus, GroupLayout.DEFAULT_SIZE,GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))));
				//.addGroup(algInfoInfoLayout.createParallelGroup(GroupLayout.Alignment.LEADING, true)
						//.addComponent(labelBeiAcando, GroupLayout.DEFAULT_SIZE,GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))));
	}
	
	private void beitragAnordnen(){
		titlebeitrag.setBorder(new LineBorder(Color.orange));
		panelBeitrag.setBorder(titlebeitrag);
		GroupLayout beitragLayout = new GroupLayout(panelBeitrag); 
		panelBeitrag.setLayout(beitragLayout);
		panelBeitrag.setBackground(Color.white);
		beitragLayout.setAutoCreateGaps(true);
		beitragLayout.setAutoCreateContainerGaps(true);

		beitragLayout.setVerticalGroup(beitragLayout.createSequentialGroup()
				.addComponent(panelBeitraege)
				.addComponent(panelEditor)
				.addComponent(panelButton));

		beitragLayout.setHorizontalGroup(beitragLayout.createParallelGroup()
				.addComponent(panelBeitraege)
				.addComponent(panelEditor)
				.addComponent(panelButton));
		
		beitraegeAnordnen();
		editorAnordnen();
		buttonAnordnen();
	}
	
	private void beitraegeAnordnen(){
		panelBeitraege.setBackground(Color.white);
		panelBeitraege.setBounds(61, 11, 81, 140);
        panelBeitraege.setLayout(new BoxLayout(panelBeitraege, BoxLayout.Y_AXIS));
        add(panelBeitraege);
        
        StringBuilder sb = new StringBuilder(64);
        sb.append("<html>Hier erscheint mein Beitrag</html>");
        
        JLabel labelDatum = new JLabel(new Date().toString()+":");
        JLabel label = new JLabel(sb.toString());
        
        panelBeitraege.add(labelDatum);
        panelBeitraege.add(label);
        
	}
	
	private void editorAnordnen(){
		panelEditor.setLayout(new FlowLayout(FlowLayout.LEFT));
		panelEditor.setBackground(Color.white);
		
		titleEditor.setBorder(new LineBorder(Color.orange));
		
		editorText = new JTextArea(5,100);
		editorText.setLineWrap(true);
		editorText.setWrapStyleWord(true);
		editorText.isEditable();
		editorText.setBorder(titleEditor);
		panelEditor.add(editorText);
	}

	private void buttonAnordnen(){
		panelButton.setBackground(Color.white);
		panelButton.setLayout(new FlowLayout(FlowLayout.LEFT));
		panelButton.add(buttonSenden);
	}

	public static void main(String args[]){
		new Home();
	}
}
